// index.js
// 获取应用实例
import {request} from "../../utils/util";
const app = getApp();
Page({
  data: {

  },
  onLoad() {
    this.getswiper();
    this.getCateList();
    this.getfloorlist();
  },
  //获取轮播图的数据
  async getswiper() {
    //获取轮播图的数据
    let res = await request({
      url: `${app.globalData.url}home/swiperdata`
    });
    //成功
    if (res.meta.status === 200) {
      this.setData({
        imgarr: res.message
      })
    } else {//失败
      wx.showToast({
        title: res.meta.msg,
        icon: 'error',
        duration: 2000
      })
    }
  },
  //获取导航信息
  async getCateList(){
    let res=await request({
      url:`${app.globalData.url}home/catitems`
    });
    //成功
    if (res.meta.status === 200) {
      //改变分类的url
      let handres=res.message.filter(item =>{
        if(item.navigator_url=="/pages/category/main"){
         return item.navigator_url="/pages/category/index"
        }else{
          return item;
        }
      })
      this.setData({
        catlist: handres
      })
    } else {//失败
      wx.showToast({
        title: res.meta.msg,
        icon: 'error',
        duration: 2000
      })
    }
  },
  //获取楼层
  async getfloorlist(){
    let res=await request({
      url:`${app.globalData.url}home/floordata`
    });
    //成功
    if (res.meta.status === 200) {
      //获取url
      let floolist=res.message.map((item)=>{
        return item;
      });
      //循环遍历改变url
      for (let i=0;i<floolist.length;i++){
        for(let g=0;g<floolist[i].product_list.length;g++){
          let befkl=floolist[i].product_list[g].navigator_url.substring(0,17);
          let artekl=floolist[i].product_list[g].navigator_url.substring(17,floolist[i].product_list[g].navigator_url.length);
          //console.log(befkl,artekl);
          let cf=befkl+'/index'+artekl;
          floolist[i].product_list[g].navigator_url=cf;
        }
      }
      // console.log(follist);
      this.setData({
        floorlist: floolist
      });
    } else {//失败
      wx.showToast({
        title: res.meta.msg,
        icon: 'error',
        duration: 2000
      })
    }
  }
})
